package com.sense.kukoo.biz_messages.adapter.provider

import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import com.d.lib.slidelayout.SlideLayout
import com.sense.kukoo.biz_messages.R
import com.sense.kukoo.biz_messages.adapter.MessagesItemAdapter
import com.sense.kukoo.common.repo.biz.MessagesItemBean
import com.sense.kukoo.common.repo.http.bean.UserMessageFollowersBean
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.utils.DataTimeUtil
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder
import com.sense.kukoo.lib_picture.config.GlideConfig
import com.sense.kukoo.lib_picture.loader.Monet

class FollowersMessagesItemProvider(
    val listener: MessagesItemAdapter.MessagesItemListener,
): MultiItemProvider<MessagesItemBean>() {

    override fun getItemType(): Int = MessagesItemBean.TYPE_FOLLOWERS

    override fun getItemLayoutId(): Int = R.layout.biz_messages_item_followers

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: MessagesItemBean) {
        val data: UserMessageFollowersBean = item.follower!!
        //
        val sl_item_messages_followers = viewHolder.getView(R.id.sl_item_messages_followers) as SlideLayout
        sl_item_messages_followers.setOpen(false, false)
        //
        val iv_icon_messages_item = viewHolder.getView(R.id.iv_icon_messages_item) as ImageView
        Monet.get(iv_icon_messages_item.context)
            .load<GlideConfig>(data.avatarUrl)
            .placeholder(com.sense.kukoo.common_design.R.drawable.design_icon_avatar_default)
            .circleCrop()
            .into(iv_icon_messages_item)
        //
        val ll_btn_follow = viewHolder.getView(R.id.ll_btn_follow) as LinearLayoutCompat
        val tv_btn_follow = viewHolder.getView(R.id.tv_btn_follow) as TextView
        if (data.isFollow()) {
            ll_btn_follow.setBackgroundResource(com.sense.kukoo.common_design.R.drawable.design_bg_btn_follow_active)
            tv_btn_follow.setTextColor(ApplicationContext.getColor(com.sense.kukoo.common_design.R.color.text_active))
            tv_btn_follow.text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.following)
        } else {
            ll_btn_follow.setBackgroundResource(com.sense.kukoo.common_design.R.drawable.design_bg_btn_follow_def)
            tv_btn_follow.setTextColor(ApplicationContext.getColor(com.sense.kukoo.common_design.R.color.text_white))
            tv_btn_follow.text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.follow)
        }
        ll_btn_follow.setOnClickListener {
            listener.onClickFollow(item)
        }
        //
        val tv_name_channel = viewHolder.getView(R.id.tv_name_channel) as TextView
        tv_name_channel.text = data.channelName
        //
        val tv_time = viewHolder.getView(R.id.tv_time) as TextView
        tv_time.text = DataTimeUtil.dateTransform1(data.createdAt)
        //
        viewHolder.getView(R.id.click_btn_item).setOnClickListener {
            listener.onClickChannel(item)
        }
        //
        viewHolder.getView(R.id.click_btn_delete).setOnClickListener {
            listener.onDeleteItem(item)
        }
    }
}